package cn.edu.dgut.utils;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;

public class ReadDB {

    public EntityManager getEntityManager(HttpServletRequest request){
        return (EntityManager) request.getAttribute("_entity.manager");
    }

    public Long getMaxNumber(HttpServletRequest request){
        EntityManager em = getEntityManager(request);
        String sql = "SELECT MAX(id) FROM user";
        Query query = em.createQuery(sql, Long.class);
        Long num = (Long) query.getSingleResult();
        return num;
    }
}
